package com.diko.vodTest;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.diko.config.exceptionhandler.myException;
import com.diko.util.AliyunVodSDKUtils;
import org.junit.Test;

import java.util.List;

/**
 * @author Emma Li
 * @date 2020/10/8 - 15:55
 */
public class testVod {
    String accessKeyId="LTAI4FzB37pVqqS4k7St7cQL";
    String accessKeySecret="9ACyOz1OQMvIPj3C3DlYx52rwVfEvK";

    /*
    * 获取视频播放凭证
    * */
    @Test
    public void testGetVideoPlayAuth()throws myException {
//创建初始化对象
        DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(accessKeyId, accessKeySecret);
        //创建获取视频凭证request和response
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        try {
            //设置请求参数，向request设置视频id
            request.setVideoId("7c89fb0fac1848438cf0bb13f6e1fb89");
            //获取请求响应，调用初始化对象的方法得到凭证
            response = client.getAcsResponse(request);
            //输出请求结果
            //播放凭证
            System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");
            //VideoMeta信息
            System.out.print("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
        System.out.print("RequestId = " + response.getRequestId() + "\n");
    }


    /*
    * 获取视频播放地址
    * */
    @Test
    public void testGetPlayInfo() throws myException {
        String accessKeyId="LTAI4FzB37pVqqS4k7St7cQL";
        String accessKeySecret="9ACyOz1OQMvIPj3C3DlYx52rwVfEvK";
        //初始化客户端、请求对象和相应对象
        DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(accessKeyId, accessKeySecret);
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        GetPlayInfoResponse response = new GetPlayInfoResponse();
        try {
            //设置请求参数
            //注意：这里只能获取非加密视频的播放地址
            request.setVideoId("7c89fb0fac1848438cf0bb13f6e1fb89");
            //获取请求响应
            response = client.getAcsResponse(request);
            //输出请求结果
            List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
            //播放地址
            for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
                System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
            }
            //Base信息
            System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
        System.out.print("RequestId = " + response.getRequestId() + "\n");
    }
}
